<template>
    <view class="page">
        <view
            v-if="currentOrderDetailData.receiveType === 1"
            class="flex_wrap row_between location"
            @click="
                currentOrderDetailData.orderStatus === 1
                    ? openAddress()
                    : openAddressed()
            "
        >
            <u-icon
                name="/pages_shop1/static/img/shop/address.png"
                size="66rpx"
            ></u-icon>
            <view class="locations">
                <view class="locations_name">
                    <text>{{ orderAddress.consigneeName || "--" }}</text>
                    <text>{{ orderAddress.consigneeMobile || "--" }}</text>
                </view>
                <view class="locations_detail">
                    {{ orderAddress.province || "--"
                    }}{{ orderAddress.city || "--"
                    }}{{ orderAddress.county || "--"
                    }}{{ orderAddress.address || "--" }}
                </view>
            </view>
            <u-icon
                name="arrow-right"
                color="#D8D8D8"
                size="18"
                v-if="currentOrderDetailData.orderStatus === 1"
            />
        </view>
        <u-gap height="14rpx" bgColor="#F5F5F5" />

        <!-- 地址弹框 -->
        <u-popup
            :round="20"
            :show="showAddress"
            @close="closeAddress"
            @open="openAddress"
            bgColor="#F6F6F6 "
        >
            <view>
                <view class="takeAddress">
                    <text>收货地址</text>
                    <view @click="closeAddress" class="closeAddress">
                        <u-icon name="close" color="#7B7B7B" size="20" bold />
                    </view>
                </view>
                <view class="manageAddress flex_wrap row_between row_middle">
                    <view>常用地址</view>
                    <view style="width: 226rpx" class="flex_wrap row_between">
                        <u-icon
                            v-if="btnShow"
                            name="/pages_shop1/static/img/shop/manage.png"
                            size="32rpx"
                            bold
                            label="管理"
                            labelSize="32rpx"
                            labelColor="#538CFF"
                            space="4rpx"
                            @click="manageBtn"
                        />
                        <u-icon
                            v-if="!btnShow"
                            name="/pages_shop1/static/img/shop/manage.png"
                            size="32rpx"
                            bold
                            label="完成"
                            labelSize="32rpx"
                            labelColor="#538CFF"
                            space="4rpx"
                            @click="finishBtn"
                        />
                        <u-icon
                            @click="addAddress"
                            name="plus"
                            size="30rpx"
                            color="#538CFF "
                            label="新增"
                            labelSize="32rpx"
                            labelColor="#538CFF"
                            space="4rpx"
                        />
                    </view>
                </view>
                <view class="noaddress" v-if="ShippingAddressList.length == 0">
                    <u-icon
                        name="/pages_shop1/static/img/shop/noaddress.png"
                        size="160rpx"
                        labelSize="28rpx"
                        labelColor="#999"
                        space="48rpx"
                        label="暂无任何收货地址"
                        labelPos="bottom"
                    />
                </view>
                <view
                    class="address_list"
                    v-if="ShippingAddressList.length > 0"
                >
                    <view v-if="btnShow" class="address_list_bg">
                        <u-radio-group
                            placement="column"
                            @change="groupChange"
                            v-model="radiovalue1"
                        >
                            <view
                                v-for="(address, index) in ShippingAddressList"
                                :key="address"
                            >
                                <view class="flex_wrap row_between">
                                    <u-icon
                                        name="/pages_shop1/static/img/shop/address.png"
                                        size="61rpx"
                                    ></u-icon>
                                    <view class="locations">
                                        <view class="locations_name flex_wrap">
                                            <text>{{
                                                address.consigneeName
                                            }}</text>
                                            <text>{{
                                                address.consigneeMobile
                                            }}</text>
                                            <text
                                                class="default"
                                                v-if="
                                                    address.defaultAddress ==
                                                    '1'
                                                "
                                            >
                                                默认
                                            </text>
                                        </view>
                                        <view class="locations_detail"
                                            >{{ address.province
                                            }}{{ address.city
                                            }}{{ address.county
                                            }}{{ address.address }}</view
                                        >
                                    </view>
                                    <u-radio
                                        v-if="btnShow"
                                        :name="address.id"
                                        :key="index"
                                        iconSize="50rpx"
                                        size="60rpx"
                                        inactiveColor="#999"
                                        activeColor="#588BF3 "
                                    />
                                </view>
                                <u-gap
                                    marginTop="32rpx"
                                    marginBottom="32rpx"
                                    height="2rpx;"
                                    bgColor="#F3F3F3"
                                />
                            </view>
                        </u-radio-group>
                    </view>
                    <!-- 点管理出现完成 -->
                    <view v-if="!btnShow" class="address_list_elsebg'">
                        <u-radio-group
                            placement="column"
                            @change="groupChange"
                            v-model="radiovalue2"
                        >
                            <view
                                v-for="(address, index) in ShippingAddressList"
                                :key="address"
                                class="address_list_elsebgList"
                            >
                                <view class="flex_wrap row_between">
                                    <u-icon
                                        name="/pages_shop1/static/img/shop/address.png"
                                        size="61rpx"
                                    ></u-icon>
                                    <view class="locations">
                                        <view class="locations_name flex_wrap">
                                            <text>{{
                                                address.consigneeName
                                            }}</text>
                                            <text>{{
                                                address.consigneeMobile
                                            }}</text>
                                            <text
                                                class="default"
                                                v-if="
                                                    address.defaultAddress ==
                                                    '1'
                                                "
                                            >
                                                默认
                                            </text>
                                        </view>
                                        <view class="locations_detail"
                                            >{{ address.province
                                            }}{{ address.city
                                            }}{{ address.county
                                            }}{{ address.address }}</view
                                        >
                                    </view>
                                    <u-icon
                                        v-if="!btnShow"
                                        name="/pages_shop1/static/img/shop/manage.png"
                                        size="40rpx"
                                        bold
                                        @click="to_edit(address.id)"
                                    />
                                </view>
                                <u-gap
                                    marginTop="32rpx"
                                    marginBottom="20rpx"
                                    height="2rpx;"
                                    bgColor="#F3F3F3"
                                />
                                <view class="flex_wrap row_between del">
                                    <u-radio
                                        label="默认地址"
                                        :name="address.id"
                                        iconSize="34rpx"
                                        labelSize="24rpx"
                                        inactiveColor="#999"
                                        activeColor="#588BF3 "
                                        @change="radioChange"
                                    />
                                    <u-text
                                        text="删除"
                                        size="24rpx"
                                        align="right"
                                        @click="del(address.id)"
                                    />
                                </view>
                            </view>
                        </u-radio-group>
                    </view>
                </view>
                <u-button
                    v-if="btnShow"
                    text="确定"
                    color="#588BF3"
                    :customStyle="{
                        ...buttonCustomStyle,
                        width: '694rpx',
                        marginBottom: '80rpx',
                    }"
                    shape="circle"
                    @click="sureAddress"
                />
            </view>
        </u-popup>

        <!-- 数据详情 -->
        <view class="item">
            <view class="item_detail flex_wrap row_between" v-for="(items,indexs) in currentOrderDetailData.orderGoodsList" :key="indexs">
                <image
                    :src="JSON.parse(items.goodsSnapshot).thumbnail"
                    mode="aspectFill"
                />
                <view>
                    <text class="total">{{
                        items.goodsName
                    }}</text>
                    <view class="detail_tt flex_wrap">
                        <text>{{
                            items.goodsSnapshot.skuSimpleSpecs
                        }}</text>
                    </view>
                    <u-gap height="26rpx" />
                    <view
                        class="flex_wrap row_between"
                        v-if="
                            items &&
                            items.goodsSnapshot
                        "
                    >
                        <u-text
                            :text="'￥' + items.goodsPrice"
                            bold
                            size="24rpx"
                        />
                        <u-text
                            :text="'x' + items.goodsCount"
                            size="26rpx"
                            align="right"
                        />
                    </view>
                </view>
            </view>
            <view class="flex_wrap row_right priceBox">
                <u-text
                    @click="to_orderClass()"
                    v-if="
                        currentOrderDetailData &&
                        (currentOrderDetailData.orderStatus === 2 ||
                            currentOrderDetailData.orderStatus === 3) &&
                        detailStatus == '0' &&
                        videoSeries
                    "
                    text="课程学习"
                    color="#588BF3"
                    size="28rpx"
                    prefixIcon="/pages_shop1/static/img/order/orderClass.png"
                    :iconStyle="{
                        width: '44rpx',
                        height: '44rpx',
                        marginRight: '10rpx',
                    }"
                />
                <u-text
                    v-if="
                        currentOrderDetailData &&
                        (currentOrderDetailData.orderStatus === 2 ||
                            currentOrderDetailData.orderStatus === 3) &&
                        detailStatus == '0' &&
                        goodsType == 'CHICKEN_FLAG'
                    "
                    @click="to_orderChicken()"
                    text="福鸡乐园"
                    color="#F79B37"
                    size="28rpx"
                    prefixIcon="/pages_shop1/static/img/order/orderChicken.png"
                    :iconStyle="{
                        width: '44rpx',
                        height: '44rpx',
                        marginRight: '10rpx',
                    }"
                />
                <view class="price">
                    <text>实付</text>
                    <text
                        class="price_t"
                        v-if="
                            currentOrderDetailData &&
                            currentOrderDetailData.orderDealAmountCent
                        "
                    >
                        ￥{{
                            currentOrderDetailData.orderDealAmountCent == 0
                                ? 0
                                : formatDecimal(
                                      numDiv(
                                          currentOrderDetailData.orderDealAmountCent,
                                          100
                                      )
                                  )
                        }}
                    </text>
                </view>
            </view>
        </view>
        <u-gap
            height="7px"
            bgColor="#F5F5F5"
            v-if="orderCouponList && orderCouponList.length > 0"
        />
        <!-- 券码信息 -->
        <!-- <view
            class="massage"
            v-if="orderCouponList && orderCouponList.length > 0"
        >
            <view class="msg_title flex_wrap row_between">
                <u-text
                    :text="
                        '券码信息' + '(' + getUsefullCoupons.length + '张可用)'
                    "
                    bold
                    color="#333"
                />
                <view style="width: 158rpx"
                    ><u-button
                        text="申请退款"
                        shape="circle"
                        :customStyle="{ height: '44rpx' }"
                        v-if="isAllRecived"
                        @click="toRefound"
                /></view>
            </view>
            <view class="msg_num">
                <view
                    class="num_list"
                    v-for="(item, index) in orderCouponList"
                    :key="item.id"
                >
                    <view class="num">
                        <view
                            class="lineThroughOut"
                            v-if="
                                item.couponStatus === 2 ||
                                item.couponStatus === 4
                            "
                        />
                        <view
                            style="display: flex"
                            :class="couponStatusClassMap[item.couponStatus]"
                            v-for="(
                                displayNumberItemOut, displayNumberItemOutIndex
                            ) in item.couponNumDisplay.split(' ')"
                            :key="displayNumberItemOut"
                        >
                            <view
                                style="width: 20rpx; text-align: center"
                                v-for="(
                                    displayNumberItemInner,
                                    displayNumberItemInnerIndex
                                ) in displayNumberItemOut.split('')"
                                :key="displayNumberItemInnerIndex"
                            >
                                {{ displayNumberItemInner }}
                            </view>
                        </view>
                    </view>
                    <view
                        class="mag_state"
                        style="
                            width: 138rpx;
                            text-align: right;
                            font-weight: bold;
                            font-size: 24rpx;
                            padding-right: 36rpx;
                        "
                        :class="couponStatusClassRightMap[item.couponStatus]"
                        @click="toRefoundResult(item)"
                    >
                        {{ couponStatusMap[item.couponStatus] }}
                    </view>
                </view>
            </view>
        </view>-->
        <u-gap height="7px" bgColor="#F5F5F5"></u-gap>
        <!-- 订单详情 -->
        <view class="orderInfo">
            <view class="orderInfoItem">
                <view class="orderInfoItem_title">订单编号</view>
                <view class="orderInfoItem_content">{{
                    currentOrderDetailData.orderNum
                }}</view>
            </view>
            <view class="orderInfoItem">
                <view class="orderInfoItem_title">创建时间</view>
                <view class="orderInfoItem_content">{{
                    currentOrderDetailData.createTime
                }}</view>
            </view>
            <view
                class="orderInfoItem"
                v-if="
                    currentOrderDetailData.orderStatus !== 1 &&
                    currentOrderDetailData.orderStatus !== 4
                "
            >
                <view class="orderInfoItem_title">支付方式</view>
                <view>{{
                    payWayMap[currentOrderDetailData.orderPaymentType]
                }}</view>
            </view>
            <view
                class="orderInfoItem"
                v-if="
                    currentOrderDetailData.orderStatus !== 1 &&
                    currentOrderDetailData.orderStatus !== 4
                "
            >
                <view class="orderInfoItem_title">付款时间</view>
                <view class="orderInfoItem_content">{{
                    currentOrderDetailData.payTime
                }}</view>
            </view>
            <view
                class="orderInfoItem"
                v-if="currentOrderDetailData.orderStatus === 3"
            >
                <view class="orderInfoItem_title">完成时间</view>
                <view class="orderInfoItem_content">{{
                    currentOrderDetailData.updateTime
                }}</view>
            </view>
            <view class="orderInfoItem">
                <view class="orderInfoItem_title">配送方式</view>
                <view class="orderInfoItem_content">{{
                    currentOrderDetailData.receiveType === 1 ? "邮寄" : "自提"
                }}</view>
            </view>
            <view
                class="orderInfoItem"
                v-if="currentOrderDetailData.orderStatus === 7"
            >
                <view class="orderInfoItem_title">订单状态</view>
                <!-- <view class="orderInfoItem_content"></view> -->
                <u-text text="退款中" color="#ff0000" align="right" />
            </view>
            <view
                class="orderInfoItem"
                v-if="currentOrderDetailData.orderStatus === 1"
            >
                <view></view>
                <view style="width: 158rpx">
                    <u-button
                        text="取消订单"
                        shape="circle"
                        :customStyle="{ height: '44rpx' }"
                        @click="cancelOrder"
                    />
                </view>
            </view>
        </view>
        <view
            class="page_bottom safeAreaBottom"
            v-if="
                currentOrderDetailData &&
                (currentOrderDetailData.orderStatus === 2 ||
                    currentOrderDetailData.orderStatus === 3) &&
                detailStatus == '0'
            "
        >
            <view class="connect" @click="connectCustomSerice">
                <view>
                    <image
                        class="connect_icon"
                        src="@/pages_shop1/static/img/order/customer_service.png"
                    ></image>
                </view>
                <view class="connect_text">联系客服</view>
            </view>
            <!-- <u-button
                text="领取"
                customStyle="width: 510rpx; height: 70rpx; border-radius: 35rpx;margin: 0;backgroundColor:#588BF3"
                type="primary"
                @click="toReceivePage"
                v-if="currentOrderDetailData.orderStatus === 2"
            />
            <u-button
                text="领取记录"
                customStyle="width: 510rpx; height: 70rpx; border-radius: 35rpx;margin: 0;backgroundColor:#588BF3"
                type="primary"
                @click="toReceiveRecord"
                v-if="currentOrderDetailData.orderStatus === 3"
            /> -->
        </view>
        <view
            class="page_bottom safeAreaBottom"
            v-if="
                currentOrderDetailData &&
                currentOrderDetailData.orderStatus === 1
            "
        >
            <u-button
                text="付款"
                customStyle="height: 70rpx; border-radius: 35rpx;margin: 0;backgroundColor:#588BF3"
                type="primary"
                @click="pay"
            />
        </view>
        <u-popup
            :show="show"
            @close="close"
            @open="open"
            mode="center"
            round="20rpx"
            closeable
        >
            <view style="width: 610rpx; height: 324rpx; padding-top: 80rpx">
                <view
                    class=""
                    style="
                        text-align: center;
                        font-size: 16px;
                        font-weight: normal;
                        line-height: 22px;
                    "
                >
                    十蜂健康客服热线
                </view>
                <view
                    class="mobile"
                    style="text-align: center; margin-top: 20rpx"
                >
                    {{ servicePhone }}
                </view>
                <view
                    class="line"
                    style="
                        width: 446rpx;
                        height: 1px;
                        border: 1px solid #f3f3f3;
                        background-color: #bbb;
                        position: relative;
                        left: calc(50% - 223rpx);
                        margin-top: 20rpx;
                    "
                ></view>
                <u-button
                    type="primary"
                    text="呼叫"
                    @click="call()"
                    customStyle="margin-top:42rpx;width:160rpx;height:44rpx;font-size: 24rpx;border-radius:22rpx"
                />
            </view>
        </u-popup>
        <u-modal
            :show="showCancelModal"
            title="提示"
            content="是否确认取消订单"
            @confirm="confirmCancelOrder"
            @cancel="cancelConfirm"
            showCancelButton
        >
            <view style="text-align: center">是否确认取消订单</view>
        </u-modal>
    </view>
</template>

<script>
import caches from "@/config/caches.js";
import { chickUrl } from "@/config/tendIdConfig.js";
import { encryption } from "@/utils/encryption.js";
import {
    getOrderDetailSalesmanByOrderNum,
    cancelOrder,
    getOrderPay,
    getProtocolByCode,
	getRememberHealthManagered
} from "@/api/order.js";
import {
    getDefaultShippingAddress,
    getShippingAddress,
    deleteAddress,
    editDefaultAddress,
    getAddressDetail,
    editAddressIdForOrder,
} from "@/api/shop.js";
import { deepClone } from "../../../utils";
import { numDiv } from "@/js_sdk/nl-precisionNum/precisionNum.js";
import { formatDecimal } from "@/utils/index.js";
export default {
    data() {
        return {
            detailStatus: "",
            ShippingAddress: {},
            orderAddress: {},
            ShippingAddressList: [],
            radiovalue1: "", //默认选中
            radiovalue2: "", //默认选中
            changeDetail: "", //切换选中的
            closeShippingAddress: "", //关闭再掉一次默认值
            btnShow: true,
            showAddress: false,
            showShare: false,
            ShippingAddress: {},
            buttonCustomStyle: {
                width: "526rpx",
                height: "80rpx",
                outline: "none",
                border: "none",
                // fontSize: '32rpx'
            },
            showCancelModal: false,
            payWayMap: {
                1: "微信",
                2: "积分",
                3: "赠送",
                4: "余额",
            },
            couponStatusMap: {
                1: "待领取",
                2: "已领取",
                3: "退款中 >",
                4: "已退款 >",
            },
            couponStatusClassMap: {
                1: "blackColor",
                2: "lineThrough",
                3: "",
                4: "lineThrough",
            },
            couponStatusClassRightMap: {
                1: "blueColor",
                2: "blackColor",
                3: "blackColor",
                4: "blackColor",
            },
            show: false,
            current: 0,
            orderId: "",
            formatDecimal: formatDecimal,
            currentOrderDetailData: null,
            orderCouponList: [],
            list1: [
                {
                    name: "全部",
                },
                {
                    name: "待付款",
                },
                {
                    name: "待领取",
                },
                {
                    name: "已完成",
                },
                {
                    name: "退款",
                },
            ],
            dataList: [1, 2, 3, 4, 5, 6, 7, 8, 9],
            numDiv, //除
            refresherStatus: 0,
            cellIconStyle: {
                width: "36rpx",
                height: "36rpx",
                marginRight: "14rpx",
            },
            cellTitleStyle: {
                fontSize: "28rpx",
                color: "#333",
            },
            servicePhone: "",
            addressType: "",
            orderPlatform: "",
            goodsType: "",
            videoSeries: "",
        };
    },
    onLoad(options) {
        this.detailStatus = options.detailStatus;
        this.orderId = options.id || "";
        if (this.orderId) {
            this.getOrderDetail(this.orderId);
        }
        this.showType();
        getProtocolByCode("CUSTOMER_SERVICE_HOTLINE").then((res) => {
            const {
                code,
                data: { customerServicePhone = "" },
            } = res;
            if (code === 200) this.servicePhone = customerServicePhone;
        });
    },
    onShow() {
        if (this.orderId) {
            this.getOrderDetail(this.orderId);
        }
        this.getShippingAddress();
        this.getDefaultShippingAddress();
    },
    computed: {
        isAllRecived() {
            return this.orderCouponList.some((item) => {
                return item.couponStatus === 1;
            });
        },
        isToScan() {
            return this.orderCouponList.some((item) => {
                return item.couponStatus === 1 || item.couponStatus === 2;
            });
        },
        getUsefullCoupons() {
            return this.orderCouponList.filter((item) => {
                return item.couponStatus === 1;
            });
        },
    },
    methods: {
        to_orderClass() {
            uni.$u.route({
                type: "redirectTo",
                url: "pages_operate/videoPage/detail",
                params: {
                    recordType: 9,
                    videoSeries: this.videoSeries,
                },
            });
        },
        to_orderChicken() {
            const phone = uni.getStorageSync(caches.PHONE);
            // 使用 uni.request 替换 wx.request，支持跨平台
            uni.request({
                url: chickUrl + "/api/v1/auth/phone-login",
                method: "POST",
                data: {
                    ...encryption({
                        user_phone: phone,
                    }),
                },
                success: (res) => {
                    this.token = res.data.data.token;
                    // 使用 uni.navigateTo 替换 wx.navigateTo，支持跨平台
                    uni.navigateTo({
                        url: `/pages_shop1/pay/chickenDetail/jump?url=${encodeURIComponent(
                            chickUrl + "/go"
                        )}&api_token=${this.token}`,
                    });
                    console.log(this.token, "11");
                },
                fail: (err) => {
                    console.log(err, "22");
                },
            });
        },
        //修改选中地址按钮
        groupChange(n) {
            this.changeDetail = this.ShippingAddressList.filter(
                (v) => v.id === n
            )[0];
        },
        radioChange(n) {
            this.changeDetail = this.ShippingAddressList.filter(
                (v) => v.id === n
            )[0];
            this.radiovalue2 = n;
        },
        // 完成按钮
        async finishBtn() {
            if (!this.radiovalue2) {
                uni.$u.toast("请先勾选默认地址！");
                return;
            }
            editDefaultAddress(this.radiovalue2).then(async (res) => {
                await (this.radiovalue1 = this.radiovalue2);
                await this.getShippingAddress();
                await this.$forceUpdate();
                this.groupChange(this.radiovalue2);
                this.btnShow = true;
            });
        },
        sureAddress() {
            this.orderAddress = this.changeDetail;
            if (!this.orderAddress) {
                uni.$u.toast("请先勾选地址！");
                return;
            }
            this.consigneeId = this.orderAddress.id;
            this.showAddress = false;
            this.changeAddressIdForOrder();
        },
        changeAddressIdForOrder() {
            const params = {
                consigneeId: this.consigneeId,
                orderNum: this.currentOrderDetailData.orderNum,
            };
            console.log(params, "params地址切换");
            editAddressIdForOrder(params).then((res) => {});
        },
        //删除地址
        del(key) {
            if (this.id == key) {
                uni.$u.toast("地址正在使用不可删除！");
                return;
            }
            const that = this;
            uni.showModal({
                title: "",
                content: "确定要删除该地址吗？",
                success({ confirm, cancel }) {
                    if (confirm) {
                        deleteAddress(key).then((res) => {
                            uni.$u.toast("删除成功！");
                            that.getShippingAddress();
                            that.getDefaultShippingAddress();
                        });
                    }
                },
            });
        },
        // 获取默认地址
        getDefaultShippingAddress() {
            getDefaultShippingAddress()
                .then((res) => {
                    if (res.code === 200) {
                        this.ShippingAddress = res.data;
                        this.radiovalue2 = this.ShippingAddress.id;
                        console.log("获取默认地址", this.radiovalue2);
                    } else {
                        uni.$u.sleep(2000).then(() => {
                            this.$refs.paging.reload();
                        });
                    }
                })
                .catch((error) => {});
        },
        closeShare() {
            this.showShare = false;
        },
        openShare() {
            this.showShare = true;
        },
        share() {
            this.showShare = true;
        },
        open() {},
        close() {
            this.show = false;
        },
        closeAddress() {
            this.showAddress = false;
            // 掉一次默认穿值给完成的默认地址
            this.getDefaultShippingAddress();
        },
        openAddressed() {},
        openAddress() {
            this.radiovalue1 = this.consigneeId;
            this.showAddress = true;
            this.btnShow = true;
            this.changeDetail = this.ShippingAddressList.filter(
                (v) => v.id === this.consigneeId
            )[0];
            console.log(
                this.changeDetail,
                this.radiovalue1,
                "打开地址选择111111111"
            );
        },
        // 获取地址列表
        getShippingAddress(pageNo, pageSize) {
            const that = this;
            const params = {
                pageNum: pageNo,
                pageSize: pageSize,
            };
            getShippingAddress(params)
                .then((res) => {
                    if (res.code === 200) {
                        this.ShippingAddressList = res.data.rows;
                    } else {
                        uni.$u.sleep(2000).then(() => {
                            this.$refs.paging.reload();
                        });
                    }
                })
                .catch((error) => {});
        },
        // 管理按钮
        manageBtn() {
            this.btnShow = false;
        },
        // 编辑按钮
        to_edit(key) {
            uni.navigateTo({
                url: "/pages_shop1/userAddress/edit?addressId=" + key,
            });
        },
        // 新增按钮
        addAddress() {
            uni.navigateTo({
                url: "/pages_shop1/userAddress/index",
            });
        },

        async pay() {
            const that = this;
            this.payButtonLoading = true;
            const { data } = await getOrderPay(
                this.currentOrderDetailData.orderNum
            );
            uni.requestPayment({
                provider: "wxpay",
                timeStamp: data.timeStamp,
                nonceStr: data.nonceStr,
                package: data.packageValue,
                signType: "MD5",
                paySign: data.paySign,
                success: function (res) {
                    if (res.errMsg === "requestPayment:ok") {
                        if (
                            that.goodsType == "CHICKEN_FLAG" &&
                            that.orderPlatform == "2"
                        ) {
                            uni.$u.route({
                                type: "redirectTo",
                                url: "pages_shop1/pay/chickenDetail/index",
                                params: {
                                    status: "success",
                                    orderNum: data.outTradeNo,
                                    productCount:
                                        that.currentOrderDetailData.goodsCount,
                                },
                            });
                        } else {
                            // uni.$u.route({
                            //     url: "pages_shop1/pay/payResult/index",
                            //     params: {
                            //         status: "success",
                            //         orderNum: data.outTradeNo,
                            //     },
                            // });
							that.getIsWeChat()
                        }
                    }
                },
                fail: function (err) {
                    console.log("fail:" + JSON.stringify(err));
                },
            });
        },
		getIsWeChat(){
			getRememberHealthManagered().then((res) => {
				console.log(res,'>>>>>>>')
				if (res.code === 200 && res.data) {
					uni.$u.route({
						type: "redirectTo",
						url: "pages_shop1/addWeChat/index",
						params: {
							wcName: res.data.nickName,
							wcImgUrl:res.data.wechatCpQrCode
						},
					});
				}else{
					uni.$u.route({
						type: "redirectTo",
						url: "pages_shop1/order/order_list/index",
					});
				}
			});
		},
        cancelOrder() {
            this.showCancelModal = true;
        },
        cancelConfirm() {
            this.showCancelModal = false;
        },
        async confirmCancelOrder() {
            const that = this;
            const params = {
                orderNum: this.currentOrderDetailData.orderNum,
            };
            const result = await cancelOrder(params);
            uni.showToast({
                title: "订单取消成功",
                icon: "success",
                success() {
                    that.showCancelModal = false;
                    that.getOrderDetail(that.orderId);
                    // uni.navigateBack();
                },
            });
        },

        toReceivePage() {
            if (!this.isToScan) {
                uni.showToast({
                    title: "暂无可领取券码",
                    icon: "error",
                });
                return;
            }
            uni.$u.route({
                url: "/pages_shop1/order/coupon/index",
                params: {
                    orderNum: this.currentOrderDetailData.orderNum,
                },
            });
        },
        toReceiveRecord() {
            uni.$u.route({
                url: "pages_shop1/order/pick_up_record/index",
                params: {
                    salesmanId: this.currentOrderDetailData.salesmanId,
                    orderNum: this.currentOrderDetailData.orderNum,
                },
            });
        },
        async getOrderDetail(orderId) {
            const result = await getOrderDetailSalesmanByOrderNum(orderId);
            if (result.data) {
                let consigneeInfo =
                    result.data.consigneeInfo &&
                    JSON.parse(result.data.consigneeInfo);
                this.orderAddress = consigneeInfo;
                this.consigneeId = result.data.consigneeId;
                this.orderPlatform = result.data.orderPlatform;
                let goodsSnapshot =
                    result.data.goodsSnapshot &&
                    JSON.parse(result.data.goodsSnapshot);
                this.goodsType = goodsSnapshot.handleFlag || null;
                this.videoSeries = goodsSnapshot.videoSeries || null;
                const simpleSpecs =
                    (goodsSnapshot.simpleSpecs &&
                        JSON.parse(goodsSnapshot.simpleSpecs)) ||
                    null;
                const skuSpecs =
                    (goodsSnapshot.skuSpecs &&
                        JSON.parse(goodsSnapshot.skuSpecs)) ||
                    null;
                goodsSnapshot.simpleSpecs = simpleSpecs || null;
                goodsSnapshot.skuSpecs = skuSpecs || null;
                const currentOrderDetailData = {
                    ...result.data,
                    goodsSnapshot,
                };
                this.currentOrderDetailData = currentOrderDetailData || null;
                this.orderCouponList =
                    currentOrderDetailData.orderCouponList || [];
            }
        },
        call() {
            uni.makePhoneCall({
                phoneNumber: this.servicePhone,
                success: (res) => {},
                fail: (res) => {},
            });
        },
        connectCustomSerice() {
            this.show = true;
        },
        close() {
            this.show = false;
        },
        open() {
            this.show = true;
        },
        showType() {
            // 使用 uni.setNavigationBarColor 替换 wx.setNavigationBarColor，支持跨平台
            uni.setNavigationBarColor({
                frontColor: "#000000",
                backgroundColor: "#ffffff",
            });
        },
        click(e) {
            this.current = e.index;
        },
        queryList(pageNo, pageSize) {
            setTimeout(() => {
                // this.$refs.paging.complete([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
                this.$refs.paging.completeByTotal(
                    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                    20
                );
            }, 500);
        },
    },
};
</script>

<style lang="scss" scoped>
.page {
    background-color: #ffffff;
    height: 100vh;
}

.location {
    padding: 40rpx 26rpx 40rpx 32rpx;
}
.locations {
    width: 100%;
    padding: 0 16rpx 0 26rpx;
    text-align: left;
    &_name {
        font-size: 28rpx;
        color: #3d3d3d;
        font-weight: 500;
        text {
            margin-right: 32rpx;
        }
        .default {
            margin-left: -12rpx;
            width: 86rpx;
            height: 36rpx;
            border-radius: 4rpx;
            border: 2rpx solid #588bf3;
            font-size: 24rpx;
            color: #588bf3;
            display: block;
            text-align: center;
            font-weight: 400;
        }
    }
    &_detail {
        size: 24rpx;
        color: #666;
        font-weight: 400;
    }
}
// 收货地址弹框
.takeAddress {
    height: 120rpx;
    background: #e2ebff;
    border-radius: 40rpx 40rpx 0rpx 0rpx;
    line-height: 120rpx;
    text-align: center;
    font-size: 40rpx;
    font-weight: 500;
    color: #3d3d3d;
}
.closeAddress {
    position: absolute;
    top: 40rpx;
    right: 32rpx;
}
.manageAddress {
    padding: 28rpx 28rpx 28rpx 40rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
}
.noaddress {
    margin: 120rpx auto 240rpx;
}
.address_list {
    padding: 0 28rpx 92rpx;
    overflow: hidden;
    &_bg {
        padding: 40rpx 28rpx 32rpx;
        max-height: 900rpx;
        background: #ffffff;
        border-radius: 20rpx;
        overflow-y: auto;
    }
    &_elsebg {
        max-height: 900rpx;
        border-radius: 20rpx;
        overflow-y: auto;
    }
    &_elsebgList {
        background: #ffffff;
        border-radius: 20rpx;
        margin-bottom: 40rpx;
        padding: 40rpx 28rpx 12rpx;
    }
}

.item {
    margin: 0 28rpx 0;
}

.item_time {
    height: 80rpx;
    border-bottom: 2rpx solid #f3f3f3;
    padding: 0 24rpx;
}

.item_detail {
    padding: 26rpx 10rpx 0;

    image {
        width: 244rpx;
        height: 158rpx;
        border-radius: 8rpx;
    }
}
.priceBox{
	border-top: 2rpx solid #f3f3f3;
	margin-top: 28rpx;
}

.total {
    display: block;
    width: 412rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: bold;
}

.detail_tt {
    margin-top: 20rpx;
    font-size: 26rpx;
    color: #666666;

    text {
        margin-right: 10rpx;
    }
}

.price {
    height: 72rpx;
    text-align: right;
    font-size: 26rpx;
    color: #ff0000;
    line-height: 72rpx;
    margin-right: 12rpx;

    .price_t {
        font-size: 30rpx;
        font-weight: bold;
    }
}

.payBtn {
    width: 158rpx;
    height: 44rpx;
    line-height: 44rpx;
    font-size: 24rpx;
    margin-right: 0;
    margin-left: 0;
    background: #588bf3;
    color: #ffffff;
    border-radius: 22rpx;
}

.cancelOrderBtn {
    width: 158rpx;
    height: 44rpx;
    line-height: 42rpx;
    font-size: 24rpx;
    margin-right: 40rpx;
    border: 1px solid #e6e6e6;
    border-radius: 22rpx;
}

.massage {
    padding: 16px 14px;
}

.num_list {
    display: flex;
    justify-content: space-between;
    margin-top: 28rpx;

    .num {
        display: flex;
        width: 280rpx;
        justify-content: space-between;
        position: relative;
        .lineThroughOut {
            width: 100%;
            position: absolute;
            border-bottom: 2rpx solid #858585;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            margin: auto;
        }

        .lineThrough {
            text-decoration: line-through;
            color: #858585;
        }

        .blackColor {
            color: #333;
        }

        .grayColor {
            color: #999;
        }
    }

    // .num.lineThrough {
    // 	text-decoration: line-through;
    // 	color: #999999;
    // }

    // .num.blackColor {
    // 	color: #333;
    // }

    // .num.grayColor {
    // 	color: #999;
    // }

    .mag_state.blackColor {
        color: #333;
    }

    .mag_state.blueColor {
        color: #588bf3;
    }

    .mag_state.grayColor {
        color: #999;
    }
}

.orderInfo {
    padding: 16px 14px;
}

.orderInfoItem {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20rpx;
    // font-size: 24rpx;
    align-items: center;
    &_title {
        color: #333;
        font-size: 28rpx;
        font-weight: bold;
    }
    &_content {
        color: #333;
        font-size: 26rpx;
    }
}

.page_bottom {
    width: 750rpx;
    min-height: 100rpx;
    position: fixed;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    background: #ffffff;
    box-shadow: 8rpx -6rpx 8rpx 0px rgba(0, 0, 0, 0.25);
    padding: 14rpx 28rpx;
}

.connect {
    display: flex;
    line-height: 72rpx;
}

.connect_icon {
    width: 32rpx;
    height: 32rpx;
    vertical-align: middle;
}

.connect_text {
    line-height: 72rpx;
}
</style>
